﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace SMS.WinForms
{
    public partial class ErrorBox : Form
    {
        public   enum   BeepType   
        {   
            SimpleBeep   =   -1,   
            IconAsterisk   =   0x00000040,   
            IconExclamation   =   0x00000030,   
            IconHand   =   0x00000010,   
            IconQuestion   =   0x00000020,   
            Ok   =   0x00000000   
        }   
        [DllImport("user32.dll")]   
        public static extern bool MessageBeep(BeepType beepType);   

        [DllImport("kernel32.dll")]   
        public static extern bool Beep(int frequency,   int duration);  

        private ErrorBox()
        {
            InitializeComponent();

            this.Size = new Size(400, 168);
        }

        public static void Show(string message, Exception exception)
        {
            ErrorBox errorBox = new ErrorBox();
            errorBox.lab_Message.Text = message;
            errorBox.txt_Detail.Text = exception.ToString();
            errorBox.ShowDialog();

        }
        public static void Show(Exception exception)
        {
            Show(exception.Message, exception);

        }

        private void btn_Detail_Click(object sender, EventArgs e)
        {
            if (this.Height == 168)
            {
                this.Height = 300;
                btn_Detail.Text = "详细(&D)↑";
            }
            else
            {
                btn_Detail.Text = "详细(&D)↓";
                this.Height = 168;
            }
        }

        private void ErrorBox_Shown(object sender, EventArgs e)
        {
            MessageBeep(BeepType.IconQuestion);
        }
    }
}
